/**
 * Created by Administrator on 2016/6/16.
 */


var page  = 1;
//自定义vue模板
var loading = false;
//分页
    $(document).ready(function(){
        $(window).scroll(function(){
            if (loading)
            {
                return;
            }
            if  ($(window).scrollTop() > $(document).height() - $(window).height() - 200)
            {
                loading = true;
                setTimeout(function(){
                    nextPage() ;
                }, 250);
            }
        });
    });


var docListMember = $("#docListMember");
//页面首次加载请求数据
$("document").ready(
    function(){
        //强制ajax同步
        var doctorList ='<section v-for="item in items" class="docListMember"><img v-if="item.nic_thumb != \'\'" v-bind:src="item.nic_thumb"><img v-if="item.nic_thumb ==\'\'" src="../images/doc_portrait.png"><section class="rightPart"><p><span>{{item.name}}</span><span>{{item.zhiwu}}</span></p><p><span>{{item.hospital_name}}</span><span>{{item.keshi}}</span></p><p><img src="../images/star.png"><span>{{item.score}}</span><span>接诊量: {{item.response_times}}</span></p><p>{{item.shan_chang_new}}</p><p class="id">{{item.d_id}}</p> </section> <section class="extra"><p class="follow_numbers">{{item.follow_numbers}}</p><p class="hospital_name">{{item.hospital_name}}</p><p class="introduce">{{item.introduce}}</p><p class="is_consult">{{item.is_consult}}</p><p class="is_follow">{{item.is_consult}}</p><p class="keshi">{{item.keshi}}</p><p class="name">{{item.name}}</p><p class="nic_thumb">{{item.nic_thumb}}</p><p class="note_num">{{item.note_num}}</p><p class="ping_num">{{item.ping_num}}</p><p class="response_times">{{item.response_times}}</p><p class="score">{{item.score}}</p><p class="shan_chang">{{item.shan_chang}}</p><p class="zhiwu">{{item.zhiwu}}</p><p class="share_url">{{item.share_url}}</p><p class="price">{{item.price}}</p></section></section>';
        $("#docListMember").append(doctorList);
        $.ajaxSettings.async=false;
        var user_token =  sessionStorage.user_token;
        $.post(commonval+"/doctorList",{
            user_token:user_token,
            device:"wap"
        },function(data){
            if(data.status == 1){
                $(".docListMember").css("display","block");
                var docListMember = new Vue({
                    el: '#docListMember',
                    data: {
                        items: data.data
                    }
                });
                $("section.docListMember").click(function(){
                    var url ="doctorInfo.html";
                    var id = $(this).children(".rightPart").children("p.id").text();
                    var follow_numbers = $(this).children(".extra").children("p.follow_numbers").text();
                    var hospital_name = $(this).children(".extra").children("p.hospital_name").text();
                    var introduce = $(this).children(".extra").children("p.introduce").text();
                    var is_consult = $(this).children(".extra").children("p.is_consult").text();
                    var is_follow = $(this).children(".extra").children("p.is_follow").text();
                    var keshi = $(this).children(".extra").children("p.keshi").text();
                    var name = $(this).children(".extra").children("p.name").text();
                    var nic_thumb = $(this).children(".extra").children("p.nic_thumb").text();
                    var note_num = $(this).children(".extra").children("p.note_num").text();
                    var ping_num = $(this).children(".extra").children("p.ping_num").text();
                    var response_times = $(this).children(".extra").children("p.response_times").text();
                    var score = $(this).children(".extra").children("p.score").text();
                    var shan_chang = $(this).children(".extra").children("p.shan_chang").text();
                    var zhiwu = $(this).children(".extra").children("p.zhiwu").text();
                    var share_url = $(this).children(".extra").children("p.share_url").text();
                    var price = $(this).children(".extra").children("p.price").text();

                    location.href = url+"?id="+id;
                    sessionStorage.d_id = id;
                    sessionStorage.Tfollow_numbers = follow_numbers;
                    sessionStorage.Thospital_name = hospital_name;
                    sessionStorage.Tintroduce = introduce;
                    sessionStorage.Tis_consult = is_consult;
                    sessionStorage.Tis_follow = is_follow;
                    sessionStorage.Tkeshi = keshi;
                    sessionStorage.Tname = name;
                    sessionStorage.Tnic_thumb = nic_thumb;
                    sessionStorage.Tnote_num = note_num;
                    sessionStorage.Tping_num = ping_num;
                    sessionStorage.Tresponse_times = response_times;
                    sessionStorage.Tscore = score;
                    sessionStorage.Tshan_chang = shan_chang;
                    sessionStorage.Tzhiwu = zhiwu;
                    sessionStorage.Tshare_url = share_url;
                    sessionStorage.Tprice = price;
                });
            }else{
                createWindow(data.msg);
                function createWindow(msg) {
                    var window =$("<section class='showMsg'></section>");
                    var show = "<p>"+msg+"</p>";
                    window.append(show);
                    $("body").append(window);
                    setTimeout("$('.showMsg').remove()",5000);
                }
            }
        })
})

//列表css交互
$("header p:nth-child(3)").on("tap",function(){
    $(".hidePlaylist").toggle();
});
$(".hidePlaylist ul li").on("tap",function(){
    $(".hidePlaylist ul li").removeClass("focus");
    $(this).addClass("focus");
    setTimeout(function(){
        $(".hidePlaylist").toggle();
        $(".hidePlaylist ul li").removeClass("active");
        $(".hidePlaylist ul li.focus").addClass("active").removeClass("focus");
    },500);
});

//列表请求排序
$(document).ready(function(){

    var type;
    $(".hidePlaylist ul li").on("tap",function(){
        var doctorList ='<section v-for="item in items" class="docListMember"><img v-if="item.nic_thumb != \'\'" v-bind:src="item.nic_thumb"><img v-if="item.nic_thumb ==\'\'" src="../images/doc_portrait.png"><section class="rightPart"><p><span>{{item.name}}</span><span>{{item.zhiwu}}</span></p><p><span>{{item.hospital_name}}</span><span>{{item.keshi}}</span></p><p><img src="../images/star.png"><span>{{item.score}}</span><span>接诊量: {{item.response_times}}</span></p><p>{{item.shan_chang_new}}</p><p class="id">{{item.d_id}}</p> </section> <section class="extra"><p class="follow_numbers">{{item.follow_numbers}}</p><p class="hospital_name">{{item.hospital_name}}</p><p class="introduce">{{item.introduce}}</p><p class="is_consult">{{item.is_consult}}</p><p class="is_follow">{{item.is_consult}}</p><p class="keshi">{{item.keshi}}</p><p class="name">{{item.name}}</p><p class="name">{{item.nic_thumb}}</p><p class="note_num">{{item.note_num}}</p><p class="ping_num">{{item.ping_num}}</p><p class="response_times">{{item.response_times}}</p><p class="score">{{item.score}}</p><p class="shan_chang">{{item.shan_chang}}</p><p class="zhiwu">{{item.zhiwu}}</p><p class="share_url">{{item.share_url}}</p></section></section>';
        $("#docListMember").empty();
        $("#docListMember").append(doctorList);

        var index = $(this).index();
        switch(index){
            case 0:
                type = "zonghe";
                $("header p:nth-child(3)").text($(this).text());
                break;
            case 1:
                type = "score";
                $("header p:nth-child(3)").text($(this).text());
                break;
            case 2:
                type = "zixun";
                $("header p:nth-child(3)").text($(this).text());
                break;
            case 3:
                type = "price_desc";
                $("header p:nth-child(3)").html("<img src='../images/priceUP.png'>");
                break;
            case 4:
                type = "price_asc";
                $("header p:nth-child(3)").html("<img src='../images/priceDown.png'>");
                break;
        }
        $.ajaxSettings.async=false;
        var user_token =  sessionStorage.user_token;
        $.post(commonval+"/doctorList",{
            user_token:user_token,
            device:"wap",
            type:type
        },function(data){
            if(data.status == 1){
                $(".docListMember").css("display","block");
                var docListMember = new Vue({
                    el: '#docListMember',
                    data: {
                        items: data.data
                    }
                });
                $("section.docListMember").click(function(){
                    var url ="doctorInfo.html";
                    var id = $(this).children(".rightPart").children("p.id").text();
                    var follow_numbers = $(this).children(".extra").children("p.follow_numbers").text();
                    var hospital_name = $(this).children(".extra").children("p.hospital_name").text();
                    var introduce = $(this).children(".extra").children("p.introduce").text();
                    var is_consult = $(this).children(".extra").children("p.is_consult").text();
                    var is_follow = $(this).children(".extra").children("p.is_follow").text();
                    var keshi = $(this).children(".extra").children("p.keshi").text();
                    var name = $(this).children(".extra").children("p.name").text();
                    var nic_thumb = $(this).children(".extra").children("p.nic_thumb").text();
                    var note_num = $(this).children(".extra").children("p.note_num").text();
                    var ping_num = $(this).children(".extra").children("p.ping_num").text();
                    var response_times = $(this).children(".extra").children("p.response_times").text();
                    var score = $(this).children(".extra").children("p.score").text();
                    var shan_chang = $(this).children(".extra").children("p.shan_chang").text();
                    var zhiwu = $(this).children(".extra").children("p.zhiwu").text();
                    var share_url = $(this).children(".extra").children("p.share_url").text();
                    location.href = url+"?id="+id;
                    sessionStorage.d_id = id;
                    sessionStorage.Tfollow_numbers = follow_numbers;
                    sessionStorage.Thospital_name = hospital_name;
                    sessionStorage.Tintroduce = introduce;
                    sessionStorage.Tis_consult = is_consult;
                    sessionStorage.Tis_follow = is_follow;
                    sessionStorage.Tkeshi = keshi;
                    sessionStorage.Tname = name;
                    sessionStorage.Tnic_thumb = nic_thumb;
                    sessionStorage.Tnote_num = note_num;
                    sessionStorage.Tping_num = ping_num;
                    sessionStorage.Tresponse_times = response_times;
                    sessionStorage.Tscore = score;
                    sessionStorage.Tshan_chang = shan_chang;
                    sessionStorage.Tzhiwu = zhiwu;
                    sessionStorage.Tshare_url = share_url;
                });
            }else{
                createWindow(data.msg);
                function createWindow(msg) {
                    var window =$("<section class='showMsg'></section>");
                    var show = "<p>"+msg+"</p>";
                    window.append(show);
                    $("body").append(window);
                    setTimeout("$('.showMsg').remove()",5000);
                }
            }
        });
    });
});
$(document).ready(function(){

});



$(document).ready(
    nextPage = function(){
     page++;
     $.ajaxSettings.async=false;
        var user_token =  sessionStorage.user_token;
     $.post(commonval+"/doctorList",{
         user_token:user_token,
         device:"wap",
         page:page
     },function(data){
         if(data.status == "1"&& data != null ){
             var doctorList ='<section v-for="item in items" class="docListMember"><img v-if="item.nic_thumb != \'\'" v-bind:src="item.nic_thumb"><img v-if="item.nic_thumb ==\'\'" src="../images/doc_portrait.png"><section class="rightPart"><p><span>{{item.name}}</span><span>{{item.zhiwu}}</span></p><p><span>{{item.hospital_name}}</span><span>{{item.keshi}}</span></p><p><img src="../images/star.png"><span>{{item.score}}</span><span>接诊量: {{item.response_times}}</span></p><p>{{item.shan_chang_new}}</p><p class="id">{{item.d_id}}</p> </section> <section class="extra"><p class="follow_numbers">{{item.follow_numbers}}</p><p class="hospital_name">{{item.hospital_name}}</p><p class="introduce">{{item.introduce}}</p><p class="is_consult">{{item.is_consult}}</p><p class="is_follow">{{item.is_consult}}</p><p class="keshi">{{item.keshi}}</p><p class="name">{{item.name}}</p><p class="name">{{item.nic_thumb}}</p><p class="note_num">{{item.note_num}}</p><p class="ping_num">{{item.ping_num}}</p><p class="response_times">{{item.response_times}}</p><p class="score">{{item.score}}</p><p class="shan_chang">{{item.shan_chang}}</p><p class="zhiwu">{{item.zhiwu}}</p><p class="share_url">{{item.share_url}}</p></section></section>';
             $("#docListMember").append(doctorList);
             $(".docListMember").css("display","block");
             var docListMember = new Vue({
                 el: '#docListMember',
                 data: {
                     items: data.data
                 }
             });
             $("section.docListMember").click(function(){
                 var url ="doctorInfo.html";
                 var id = $(this).children(".rightPart").children("p.id").text();
                 var follow_numbers = $(this).children(".extra").children("p.follow_numbers").text();
                 var hospital_name = $(this).children(".extra").children("p.hospital_name").text();
                 var introduce = $(this).children(".extra").children("p.introduce").text();
                 var is_consult = $(this).children(".extra").children("p.is_consult").text();
                 var is_follow = $(this).children(".extra").children("p.is_follow").text();
                 var keshi = $(this).children(".extra").children("p.keshi").text();
                 var name = $(this).children(".extra").children("p.name").text();
                 var nic_thumb = $(this).children(".extra").children("p.nic_thumb").text();
                 var note_num = $(this).children(".extra").children("p.note_num").text();
                 var ping_num = $(this).children(".extra").children("p.ping_num").text();
                 var response_times = $(this).children(".extra").children("p.response_times").text();
                 var score = $(this).children(".extra").children("p.score").text();
                 var shan_chang = $(this).children(".extra").children("p.shan_chang").text();
                 var zhiwu = $(this).children(".extra").children("p.zhiwu").text();
                 var share_url = $(this).children(".extra").children("p.share_url").text();
                 location.href = url+"?id="+id;
                 sessionStorage.d_id = id;
                 sessionStorage.Tfollow_numbers = follow_numbers;
                 sessionStorage.Thospital_name = hospital_name;
                 sessionStorage.Tintroduce = introduce;
                 sessionStorage.Tis_consult = is_consult;
                 sessionStorage.Tis_follow = is_follow;
                 sessionStorage.Tkeshi = keshi;
                 sessionStorage.Tname = name;
                 sessionStorage.Tnic_thumb = nic_thumb;
                 sessionStorage.Tnote_num = note_num;
                 sessionStorage.Tping_num = ping_num;
                 sessionStorage.Tresponse_times = response_times;
                 sessionStorage.Tscore = score;
                 sessionStorage.Tshan_chang = shan_chang;
                 sessionStorage.Tzhiwu = zhiwu;
                 sessionStorage.Tshare_url = share_url;
             });
         }else{
             page--;
         }
     });
  }
);

//var user_token =  sessionStorage.user_token;
//$.post("http://dev.haotoufa.com/index",{
//    user_token:user_token,
//    device:"wap",
//},function(data) {
//    console.log(data.data);
//})





